using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;
using UnityEngine.UIElements;

public class Grind : MonoBehaviour
{
    // Start is called before the first frame update
    public GameObject[] grinding1,grinding2;
    Transform ttransform;
    Transform playertransform;
    bool firstingrind2;
    bool nearby;
    void Start()
    {
        ttransform = GetComponent<Transform>();
        playertransform = GameObject.FindWithTag("Player").GetComponent<Transform>();
        firstingrind2 = false;
        nearby = false;
    }
    private void Update()
    {
        if (Mathf.Abs(playertransform.position.x - ttransform.position.x) < 120f)
            nearby = true;
    }
    // Update is called once per frame
    void grind1()
    {
        if (!nearby) return;
        if (transform.childCount > 32) return;
        for (int i = 1; i <= 4; i++)
        {
            Vector3 position = ttransform.position;
            position.x += Random.Range(-3.0f, 3.0f);
            Instantiate(grinding1[Random.Range(0, grinding1.Length)], position, Quaternion.identity,transform);
        }
        
    }
    void grind2()
    {
        if (!nearby) return;
        if (transform.childCount > 32) return;
        if (firstingrind2==false)
        {
            firstingrind2 = true;
            return;
        }
        for (int i = 1; i <= 2; i++)
        {
            Vector3 position = ttransform.position;
            position.x += Random.Range(-3.0f, 3.0f);
            Instantiate(grinding2[Random.Range(0, grinding2.Length)], position, Quaternion.identity,transform);
        }

    }
}